package com.yeyaomai.dksns.flowis.util;

import java.math.BigDecimal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author dingtao@yeyaomai.com
 * 
 *   TODO Apache 有现成的工具类
 * 
 */
public class NumberFormatUtils {

	private static Logger logger = LoggerFactory
			.getLogger(NumberFormatUtils.class);

	public static int resolveString(String str, int def) {

		try {
			def = Integer.parseInt(str);
		} catch (NumberFormatException e) {
			logger.warn("类型转换出错--" + str + e);
		}

		return def;
	}
	
	public static BigDecimal roundNumber(double divisor, double dividend){ 
		BigDecimal bd=new BigDecimal(0); 
		if(divisor!=0.0&&dividend!=0.0){
			bd=new BigDecimal(divisor/dividend).setScale(2,BigDecimal.ROUND_HALF_UP);
		}
		return bd;
	}

}
